package com.ruoyi.bbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bbs.domain.BbsForum;
import com.ruoyi.bbs.service.IBbsForumService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 分区Controller
 * 
 * @author saruri
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/forum")
public class BbsForumController extends BaseController
{
    @Autowired
    private IBbsForumService bbsForumService;

    /**
     * 查询分区列表
     */
    @RequiresPermissions("bbs:forum:list")
    @GetMapping("/list")
    public TableDataInfo list(BbsForum bbsForum)
    {
        startPage();
        List<BbsForum> list = bbsForumService.selectBbsForumList(bbsForum);
        return getDataTable(list);
    }

    /**
     * 导出分区列表
     */
    @RequiresPermissions("bbs:forum:export")
    @Log(title = "分区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BbsForum bbsForum)
    {
        List<BbsForum> list = bbsForumService.selectBbsForumList(bbsForum);
        ExcelUtil<BbsForum> util = new ExcelUtil<BbsForum>(BbsForum.class);
        util.exportExcel(response, list, "分区数据");
    }

    /**
     * 获取分区详细信息
     */
    @RequiresPermissions("bbs:forum:query")
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") Long fid)
    {
        return success(bbsForumService.selectBbsForumByFid(fid));
    }

    /**
     * 新增分区
     */
    @RequiresPermissions("bbs:forum:add")
    @Log(title = "分区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BbsForum bbsForum)
    {
        return toAjax(bbsForumService.insertBbsForum(bbsForum));
    }

    /**
     * 修改分区
     */
    @RequiresPermissions("bbs:forum:edit")
    @Log(title = "分区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BbsForum bbsForum)
    {
        return toAjax(bbsForumService.updateBbsForum(bbsForum));
    }

    /**
     * 删除分区
     */
    @RequiresPermissions("bbs:forum:remove")
    @Log(title = "分区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable Long[] fids)
    {
        return toAjax(bbsForumService.deleteBbsForumByFids(fids));
    }
}
